package thread;

public class Bank {
    private  int account = 20000;

    public synchronized boolean getMoney(int money){
        int account = getAccount();
        if (account >= money){
            account = account - money;
            //Thread.yield();//模拟时间片耗尽
            setAccount(account);
            return true;
        }
        return false;
    }

    public int getAccount() {
        return account;
    }

    public void setAccount(int account) {
        this.account = account;
    }
}
